package booksystem.dao.impl;

import booksystem.dao.BaseDao;
import booksystem.dao.BookDao;
import booksystem.entity.Book;

import java.util.List;

public class BookDaoImpl extends BaseDao<Book> implements BookDao {

    @Override
    public Book getBookDetail(String id) {
        String sql = "select * from book where id=?";
        return getBean(Book.class, sql, id);
    }

    @Override
    public List<Book> getAllBook() {
        String sql = "select * from book order by id desc";
        return getBeanList(Book.class, sql);
    }

    @Override
    public int deleteBook(String id) {
        String sql = "delete from book where id=?";
        return update(sql, id);
    }

    @Override
    public int saveBook(Book book) {
        String sql = "insert into book(name, author, publish, ISBN, publish_time, detail, author_detail, context, price, cover, classify) value(?,?,?,?,?,?,?,?,?,?,?)";
        return update(sql, book.getName(), book.getAuthor(), book.getPublish(), book.getISBN(), book.getPublish_time(), book.getDetail(), book.getAuthor_detail(), book.getContext(), book.getPrice(), book.getCover(), book.getClassify());
    }

    @Override
    public List<Book> getClassifyBook(String classify) {
        String sql = "select * from book where classify=? order by id desc";
        return getBeanList(Book.class, sql, classify);
    }


}
